///<reference path="../typings/tsd.d.ts" />
//通过地址栏传入id,node.  如果id为null,则是新增，反之是修改
$(function() {
    var querystring = window.location.search;
    //let xmid = (querystring.match(/xmid=(\w*)/))[1];   //匹配不上，则为空字符串
    let zzjgid = parent.CurTreeNode.ID;
    let nodeidx = (querystring.match(/node=(\w+)/))[1];
    let INFO: NodeOptions = window.NODE[nodeidx];
    let id="";
    if(nodeidx=="zhtj"){
        id=(querystring.match(/xmid=(\w*)/))[1];
    }else{
        id=(querystring.match(/id=(\w*)/))[1];
    }
    let title = (id == "" ? "新增" : "编辑");

    $(".title_left").text(title + "----" + INFO.title);
    /**关闭窗体 */
    function closeMe() {
        window.parent.$('#topTabs').tabs('close', title);
    }
    /**弹出成功提示 */
    function alertOk() {
        $.auto.alert("提示","保存成功！");
    }
    /**如果是项目综合统计，在新增时，需要把组织机构id传入 */
    function insertZZjgid(updata:any) {
        if(nodeidx=="zhtj" &&title=="新增")
        {updata.push({name:"ZZJGID",value:parent.CurTreeNode.ID});}
    }
    if (id != "") {
        $.ajax(INFO.querybyIDUrl, { type: 'POST', data: { id: id,tableName:INFO.view }, dataType: 'json' })
            .done(function(row) {
                let opt: AutoFormOption = { values: row,
                     canceled: closeMe ,saved:alertOk};
                $.extend(opt,INFO.formOpt);
                $("#editFrm").autoForm(opt);
            });
    }
    else {
        $("#editFrm").autoForm($.extend({ canceled: closeMe,saved:alertOk,beforeSave:insertZZjgid }, INFO.formOpt));
    }




})